import { createRouter, createWebHashHistory } from "vue-router";
import store from "../store";
import LeftSideMenu from "./LeftSideMenu";
import rests from "./rests";
import configuration from "./configuration";
import video from "./video";
import beRelieved from "./beRelieved";
import communication from "./communication";
import dxgw from "./dxgj";
import comsenz from "./comsenz";
import abb from "./abb";
import kx from "./kx";
import writ from "./writ";
import djhs from "./djhs";
import cyyx from "./cyyx";
import jk from "./jk";
import hz from "./hz";
import BOTTEGA from "./BOTTEGA";
import salesManagement from "./salesManagement";
import phoneyz from "./phoneyz";
import xqts from "./xqts";
import shm from "./shm";
import tutu from "./tutu";
import mh from "./mh";
import xinglianxin from "./xinglianxin";
import fapiao from "./fapiao";
import hnlq from "./hnlq";
import cgkj from "./cgkj";
import ArticlePublishing from "./ArticlePublishing";
import yida from "./yida";
import chatGPT from "./chatGPT";
import videomsg from "./videomsg";
import xjyx from "./xjyx";
import RedEnvelopeLuckyDraw from "./RedEnvelopeLuckyDraw";
import excleTojpg from "./excleTojpg";
import shbq from "./shbq";
import hhscdd from "./hhscdd";
import studyAbroad from "./studyAbroad";
import invitationCode from "./invitationCode";
import hjq from "./hjq";
import banglingju from "./banglingju";
import zwzz from "./zwzz";
import yuyue from "./yuyue";
import skzn from "./skzn";
import xtgx from "./xtgx";
import gjx from "./gjx";
import gjxbj from "./gjxbj";
import mfh from "./mfh";
import hlxn from "./hlxn";
import riceRabbit from "./riceRabbit";
import courseManagement from "./courseManagement";
import jiacaihui from "./jiacaihui";
import gudrYun from "./gudrYun";

import gsjjxcx from "./gsjjxcx";
import meirong from "./meirong";

import luodiye from "./luodiye";
import xinxi100 from "./xinxi100";
import maya from "./maya";
import tjxx from "./tjxx";
import xiaoming from "./xiaoming";
import cbrc from "./cbrc";
import jyc from "./jyc";
import jiance from "./jiance";
import fwm from "./fwm";
import xhkj from "./xhkj";
import meilong from "./meilong";
import { initXx } from "../util/xgData";

const routes = [
  ...LeftSideMenu,
  ...rests,
  ...configuration,
  ...video,
  ...communication,
  ...beRelieved,
  ...comsenz,
  ...abb,
  ...dxgw,
  ...kx,
  ...writ,
  ...djhs,
  ...cyyx,
  ...jk,
  ...hz,
  ...BOTTEGA,
  ...salesManagement,
  ...phoneyz,
  ...xqts,
  ...shm,
  ...tutu,
  ...mh,
  ...xinglianxin,
  ...fapiao,
  ...hnlq,
  ...cgkj,
  ...ArticlePublishing,
  ...yida,
  ...chatGPT,
  ...videomsg,
  ...RedEnvelopeLuckyDraw,
  ...xjyx,
  ...excleTojpg,
  ...shbq,
  ...hhscdd,
  ...studyAbroad,
  ...invitationCode,
  ...hjq,
  ...banglingju,
  ...zwzz,
  ...yuyue,
  ...skzn,
  ...xtgx,
  ...gjx,
  ...gjxbj,
  ...mfh,
  ...hlxn,
  ...riceRabbit,
  ...courseManagement,
  ...jiacaihui,
  ...gudrYun,
  ...gsjjxcx,
  ...meirong,
  ...luodiye,
  ...xinxi100,
  ...maya,
  ...tjxx,
  ...xiaoming,
  ...cbrc,
  ...jyc,
  ...jiance,
  ...fwm,
  ...xhkj,
  ...meilong

];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach(async (to: any, from, next) => {
  store.state.lyName = to.meta.name;
  document.title = to.meta.title;
  if (to.name == "wx") {
    next();
    return;
  }
  store.state.storequery = to.query
  store.state.IfTheFullScreen = to.meta.IfTheFullScreen;
  store.state.routerName = to.name;
  store.commit("setrouterList", routes);;

  if (to.query.ck != 3) {
    store.commit("setmenumg");
  } else {
    store.state.accountType = 2
    store.state.isheader = false
  }


  store.commit("setrolemanagement");
  store.commit("isOpenTheMenu");
  if (!localStorage.formList) {
    localStorage.formList = JSON.stringify(initXx);
  }
  // if(localStorage.accountType==2){ //监控的前端
  //   next('leadingEnd');
  //   return
  // }
  if (
    to.name == "index" &&
    localStorage.index != "null" &&
    localStorage.index != "/"
  ) {
    next(localStorage.index);
  } else {
    next();
  }
});

export default router;
